package Demo.controller;

import Demo.mapper.IUserMapper;
import Demo.pojio.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Scanner;
@Component
public class UserController {
    @Autowired
    private IUserMapper userMapper;
    public void start(){
        System.out.println("UserController:启动服务...");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入服务内容编号：");
        System.out.println("1、注册");
        System.out.println("2、登录");
        System.out.println("3、修改密码");
        System.out.println("4、用户列表");
        int num = scanner.nextInt();
        switch (num){
            case 1:
                System.out.println("1、注册");
                regUser();
                break;
            case 2:
                System.out.println("2、登录");
                break;
            case 3:
                System.out.println("3、修改密码");
                break;
            case 4:
                System.out.println("4、用户列表");
                break;
        }
    }
    public void regUser(){
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入用户名：");
        String username = scanner.next();
        System.out.println("请输入密码：");
        String password = scanner.next();
        System.out.println("请输入昵称：");
        String nickname = scanner.next();
        int age = scanner.nextInt();
        if (username == null || password == null || nickname == null || age == 0){
            System.out.println("用户名、密码、昵称、年龄不能为空");
        }
        User user = new User(0,username,password,nickname,age);
        int resalt = userMapper.insertUser(user);
        if (resalt > 0){
            System.out.println("注册成功！");
        }else {
            System.out.println("注册失败！");
        }
    }
}
